package com.zs4sdk.entity;

import com.common.library.entity.JSONResultEntity;
import com.common.library.util.Helper;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 
 * function: 微信订单返回json类
 * 
 * @ author: aXiBa
 */
public class WXOrderResultEntity extends JSONResultEntity {

	public static final String COLUMN_ERRCODE = "errcode";
	public static final String COLUMN_MESSAGE = "message";
	public static final String COLUMN_WXAPPID = "appid";
	public static final String COLUMN_PARTNERID = "partnerid";
	public static final String COLUMN_PREPAYID = "prepayid";
	public static final String COLUMN_PACKAGE = "package";
	public static final String COLUMN_NONCESTR = "noncestr";
	public static final String COLUMN_TIMESTAMP = "timestamp";
	public static final String COLUMN_SIGN = "sign";
	public static final String COLUMN_VERSION = "version";

	private String message;
	private String errcode;
	private String wxappid;
	private String partnerid;
	private String prepayid;
	private String packages;
	private String noncestr;
	private String timestamp;
	private String sign;
	private boolean success;
	private String version;


	/**
	 * 构造方法
	 */
	public WXOrderResultEntity(){

	}
	/**
	 * 构造方法
	 * @param json
	 */
	public WXOrderResultEntity(JSONObject json){
		this.fromJSON(json);
	}
	/**
	 * 构造方法
	 * @param jsonStr
	 */
	public WXOrderResultEntity(String jsonStr){
		try{
			this.fromJSON(new JSONObject(jsonStr));
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	//#endregion 构造方法

	//#region Override方法
	@Override
	public JSONObject toJSON() {
		JSONObject result = super.toJSON();
		try {
			result.put(COLUMN_MESSAGE, this.message);
			result.put(COLUMN_ERRCODE, this.errcode);
			result.put(COLUMN_WXAPPID, this.wxappid);
			result.put(COLUMN_PARTNERID, this.partnerid);
			result.put(COLUMN_PREPAYID, this.prepayid);
			result.put(COLUMN_PACKAGE, this.packages);
			result.put(COLUMN_NONCESTR, this.noncestr);
			result.put(COLUMN_TIMESTAMP, this.timestamp);
			result.put(COLUMN_SIGN, this.sign);
			result.put(COLUMN_VERSION, this.version);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	@Override
	public void fromJSON(JSONObject json) {
		super.fromJSON(json);
		if (Helper.isNotEmpty(json)) {
			this.message = json.optString(COLUMN_MESSAGE);
			this.errcode = json.optString(COLUMN_ERRCODE);
			this.wxappid = json.optString(COLUMN_WXAPPID);
			this.partnerid = json.optString(COLUMN_PARTNERID);
			this.prepayid = json.optString(COLUMN_PREPAYID);
			this.packages = json.optString(COLUMN_PACKAGE);
			this.noncestr = json.optString(COLUMN_NONCESTR);
			this.timestamp = json.optString(COLUMN_TIMESTAMP);
			this.sign = json.optString(COLUMN_SIGN);
			this.version = json.optString(COLUMN_VERSION);
		}
	}

	/**
	 * 是否成功
	 */
	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getNoncestr() {
		return noncestr;
	}

	public void setNoncestr(String noncestr) {
		this.noncestr = noncestr;
	}

	public String getPackages() {
		return packages;
	}

	public void setPackages(String packages) {
		this.packages = packages;
	}

	public String getPartnerid() {
		return partnerid;
	}

	public void setPartnerid(String partnerid) {
		this.partnerid = partnerid;
	}

	public String getPrepayid() {
		return prepayid;
	}

	public void setPrepayid(String prepayid) {
		this.prepayid = prepayid;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public String getWxappid() {
		return wxappid;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public void setWxappid(String wxappid) {
		this.wxappid = wxappid;
	}

	//是否请求订单成功
	@Override
	public boolean isSuccess() {
		if(getErrcode().equals("0")){
			return true;
		}else return false;
	}
}
